package Test;

import com.pojo.Employee;
import com.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

public class EmployeeTest {
    @Test
    public void findEmployeeById() {
        SqlSession session = MyBatisUtils.getSqlSession();
        Employee employee = session.selectOne("com.mapper.EmployeeMapper.selectByPrimaryKey", (long)1);
        System.out.println(employee);
        session.commit();//提交事务
        session.close();//关闭链接
    }
    @Test
    public void addEmployeeTest(){
        SqlSession session = MyBatisUtils.getSqlSession();
        Employee employee = new Employee();
        employee.setName("王八");
        employee.setAge(25);
        employee.setPosition("总裁");
        int rows = session.insert("com.mapper.EmployeeMapper.insert",employee);
        System.out.println(rows);
        session.commit();//提交事务
        session.close();//关闭链接
    }
    @Test
    public void updateEmployeeTest(){
        SqlSession session = MyBatisUtils.getSqlSession();
        Employee employee = new Employee();
        employee.setId(3);
        employee.setName("李四");
        employee.setAge(50);
        employee.setPosition("董事长");
        int rows = session.update("com.mapper.EmployeeMapper.updateByPrimaryKey",employee);
        System.out.println(rows);
        session.commit();//提交事务
        session.close();//关闭链接
    }
    @Test
    public void deleteEmployeeTest(){
        SqlSession session = MyBatisUtils.getSqlSession();
        int rows = session.delete("com.mapper.EmployeeMapper.deleteByPrimaryKey",3L);
        System.out.println(rows);
        session.commit();//提交事务
        session.close();//关闭链接
    }
}
